package com.itheima.day15.TCP.test3;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

// 服务器
public class ServerDemo {
    public static void main(String[] args) throws IOException {
        // 1.创建ServerSocket
        ServerSocket ss = new ServerSocket(10004);

        // 2.等待客户端连接
        Socket accept = ss.accept();

        // 3.创建转换流接收
        System.out.println(2);
        BufferedReader br = new BufferedReader(new InputStreamReader(accept.getInputStream()));
        String str;
        while ((str = br.readLine()) != null) {
            System.out.println(str);
        }

        // 4.返回响应
        System.out.println(3);
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(accept.getOutputStream()));
        bw.write("你是傻逼");
        bw.newLine();
        bw.flush();

        accept.close();
        ss.close();

    }
}
